#include "collectorprotocol.h"
#include "collectorsendpacket.h"
#include "collectorparsepacket.h"
#include "collectorprotocoldata.h"
#include "collectorparsesystempacket.h"
#include "collectorsendsystempacket.h"
#include "common/makepacket.h"
#include "common/findpacket.h"

namespace hplc
{
namespace qinfine
{

CollectorProtocol::CollectorProtocol(CollectorParam &param, QObject *parent)
    : CollectorProtocol (*new CollectorProtocolData(), param, parent)
{

}

CollectorProtocol::CollectorProtocol(CollectorProtocolData &data, CollectorParam &param, QObject *parent)
    : ProtocolCommon (data, param, parent)
    , m_param(&param)
{
    CollectorParsePacket *parser = new CollectorParsePacket(data, param, this);
    CollectorSendPacket *sender = new CollectorSendPacket (data, this);
    connect(sender, &SendCommonPacket::requestSend, this, &ProtocolCommon::requestSend);

    CollectorParseSystemPacket *systemParser = new CollectorParseSystemPacket(data, param, this);
    CollectorSendSystemPacket *systemSender = new CollectorSendSystemPacket(data);

    data.m_parser = parser;
    data.m_sender = sender;
    data.m_systemParser = systemParser;
    data.m_systemSender = systemSender;
}

CollectorProtocol::~CollectorProtocol()
{
    CollectorProtocolData *d = static_cast<CollectorProtocolData*>(m_d);
    delete d->m_sender;
    delete d->m_parser;
    delete d->m_systemParser;
    delete d->m_systemSender;
}

bool CollectorProtocol::setProtocolCmd(int id, QVariant &var)
{
    return ProtocolCommon::setProtocolCmd(id, var);
}

bool CollectorProtocol::getProtocolCmd(int id, QVariant &var)
{
    return ProtocolCommon::getProtocolCmd(id, var);
}

CollectorSendPacket *CollectorProtocol::getCollectorSender()
{
    return static_cast<CollectorSendPacket*>(m_d->m_sender);
}

CollectorSendSystemPacket *CollectorProtocol::getCollectorSystemSender()
{
    CollectorProtocolData *m_d = static_cast<CollectorProtocolData*>(this->m_d);
    return m_d->m_systemSender;
}

void CollectorProtocol::setModel(quint8 model)
{
//    m_param->
}

} // qinfine
} // hplc
